﻿//
// Created by Administrator on 2022/6/16.
//

#include <wx/cmdline.h>
#include "MyApp.h"
#include "MyDialog.h"

IMPLEMENT_APP ( MyApp )


static const wxCmdLineEntryDesc cmdLineDesc[] =
        {
                { wxCMD_LINE_SWITCH, ("h"), "help",
                  "show this help message",
                  wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
                { wxCMD_LINE_SWITCH, "s", "secret",
                  "a secret switch",
                  wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN },
                // ... your other command line options here...
                { wxCMD_LINE_SWITCH, "l", "list",
                  "process a file list",
                  wxCMD_LINE_VAL_STRING, 0 },
                { wxCMD_LINE_SWITCH, "f", "file",
                  "process a file",
                  wxCMD_LINE_VAL_STRING, 0 },
                { wxCMD_LINE_SWITCH, "d", "dir", "process a dir",
                  wxCMD_LINE_VAL_STRING, 0 },
                //{ wxCMD_LINE_OPTION, ("d"), ("debug"), ("specify a debug level") },
                { wxCMD_LINE_SWITCH, "D", "delete",
                  "remove file after post",
                  wxCMD_LINE_VAL_STRING, 0 },
                { wxCMD_LINE_PARAM,  nullptr, nullptr, ("input file"),
                  wxCMD_LINE_VAL_STRING,
                  wxCMD_LINE_PARAM_OPTIONAL },
                wxCMD_LINE_DESC_END
        };

/*
 * --list
 * -h
 * -l
 * -h -f
 * -l -f 1
 * "-h" res=1, then show the usage
 */
bool MyApp::OnInit() {
    wxString cmdFilename;
    wxCmdLineParser cmdParser( cmdLineDesc, argc, argv );
    int res;

    wxLogNull log;
    // 传递False参数以便在分析命名行发生错误的时候不显示使用帮助对话框.
    res = cmdParser.Parse(false);
    // 检查是否用户正在询问使用帮助
    //switch (cmdParser.Parse()) {
    switch ( res ) {
        case -1:
            //help
            break;
        case 0:
            if (cmdParser.Found("f")) {
                wxString cmdFilename = cmdParser.GetParam(0);
                cmdFilename.Replace("\\", "/");
            }
            if (cmdParser.Found("l")) {
                wxString Delete = cmdParser.GetParam(0);
            }
            break;
        default:
            break;
    };

    if ( cmdParser.GetParamCount() != 0 )
    {
        //wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
        wxString cmdFilename = cmdParser.GetParam(0);

    }
    auto *dialog = new MyDialog();
    dialog->Show();
    return true;
}

int MyApp::OnExit() {

    return 0;
}